package com.kalian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kalian.dao.UserDao;
import com.kalian.pojo.User;
import com.kalian.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserDao userDao;

    @Override
    public Page<User> page(int page, int pageSize, String name) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.like("username",name);
        return userDao.selectPage(new Page<>(page,pageSize),qw );
    }

    @Override
    public void save(User user) {
        userDao.insert(user);
    }

    @Override
    public void del(int id) {
        userDao.deleteById(id);
    }

    @Override
    public List<User> findName(String name) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.like("username",name);
        return userDao.selectList(qw);
    }
}
